package cn.xhc.users.service.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;

import cn.xhc.common.util.JsonUtil;
import cn.xhc.common.util.PageInfoUtil;
import cn.xhc.users.dao.IAAdminsDao;
import cn.xhc.users.dao.IARoleDao;
import cn.xhc.users.pojo.AAdmins;
import cn.xhc.users.pojo.ARole;
import cn.xhc.users.service.IUsersService;
@Service("usersService")
public class UsersServiceImpl implements IUsersService{
	@Resource
	private IAAdminsDao adminsDao;
	@Resource
	private IARoleDao roleDao;
	/*管理员模块开始*/
	/**
	 * 查询一条管理员
	 */
	@Override
	public AAdmins findOneAdminService(Map<String, Object> condMap) {
		return adminsDao.findOne(condMap);
	}
	/**
	 * 保存一条管理员
	 */
	@Override
	public JSONObject saveOneAdminService(AAdmins admins) {
		int result = this.adminsDao.saveOne(admins);
		return JsonUtil.JsonHandler(result,admins.getId());
	}
	/**
	 * 更新一个管理员
	 */
	@Override
	public JSONObject updateOneAdminService(AAdmins admins) {
		int result = this.adminsDao.updateOne(admins);
		return JsonUtil.JsonHandler(result,admins.getId());
	}
	/**
	 * 删除一个管理员
	 */
	@Override
	public JSONObject deleteOneAdminService(AAdmins admins) {
		int result = this.adminsDao.deleteOne(admins);
		return JsonUtil.JsonHandler(result, admins.getId());
	}
	/**
	 * 查询所有管理员信息
	 */
	@Override
	public List<AAdmins> findCondListAdminService(PageInfoUtil pageInfoUtil,Map<String, Object> condMap) {
		if(pageInfoUtil != null){
			/**分页*/
			Page<AAdmins> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<AAdmins> adminList = this.adminsDao.findCondList(condMap);
			/**设置总记录数*/
			pageInfoUtil.setTotalRecord(Integer.parseInt(page.getTotal()+""));
			return adminList;
		}
		return this.adminsDao.findCondList(condMap);
	}
	
	/*管理员模块结束*/
	
	/*角色模块开始*/
	/**
	 * 查询一条角色
	 */
	@Override
	public ARole findOneRoleService(Map<String, Object> condMap) {
		return roleDao.findOne(condMap);
	}
	/**
	 * 保存一条角色
	 */
	@Override
	public JSONObject saveOneRoleService(ARole role) {
		int result = this.roleDao.saveOne(role);
		return JsonUtil.JsonHandler(result,role.getId());
	}
	/**
	 * 更新一个角色
	 */
	@Override
	public JSONObject updateOneRoleService(ARole role) {
		int result = this.roleDao.updateOne(role);
		return JsonUtil.JsonHandler(result,role.getId());
	}
	/**
	 * 删除一个角色
	 */
	@Override
	public JSONObject deleteOneRoleService(ARole role) {
		int result = this.roleDao.deleteOne(role);
		return JsonUtil.JsonHandler(result, role.getId());
	}
	/**
	 * 查询所有角色信息
	 */
	@Override
	public List<ARole> findCondListRoleService(PageInfoUtil pageInfoUtil,Map<String, Object> condMap) {
		if(pageInfoUtil != null){
			/**分页*/
			Page<ARole> page = PageHelper.startPage(pageInfoUtil.getCurrentPage(), pageInfoUtil.getPageSize());
			List<ARole> adminList = this.roleDao.findCondList(condMap);
			/**设置总记录数*/
			pageInfoUtil.setTotalRecord(Integer.parseInt(page.getTotal()+""));
			return adminList;
		}
		return this.roleDao.findCondList(condMap);
	}
	
	/*角色模块结束*/
	

}
